package com.demo.template.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
//@LoadBalancerClient(value = "nacos-discovery", configuration = MySelfLoadBalancedConfig.class)
@LoadBalancerClients(
        value = {
                @LoadBalancerClient(value = "nacos-discovery", configuration = MySelfLoadBalancedConfig.class)
        },
        defaultConfiguration = RandomLoadBalancedConfig.class
)
public class TemplateConfig {

    /**
     * @LoadBalanced 自动为RestTemplate设置负载均衡策略。
     * 定义一个带有负载均衡的 restTemplate
     * */
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}
